/**
 * 图层
 *
 * 用法
 *    import { layer } from './utils'
 *    layer.enable(room, 2)
 *    layer.disable(room, 2)
 *
 *    const raycaster = new THREE.Raycaster()
 *    layer.setRaycaster(raycaster, 2)
 */
import * as THREE from 'three'

// 启用图层
function enable(object: THREE.Object3D, layer: number) {
  object.traverse((node) => {
    node.layers.enable(layer)
  })
}

// 禁用图层
function disable(object: THREE.Object3D, layer: number) {
  object.traverse((node) => {
    node.layers.disable(layer)
  })
}

// 禁用所有图层
function disableAll(object: THREE.Object3D) {
  object.traverse((node) => {
    node.layers.disableAll()
  })
}

// 为光线拾取器设置图层
function setRaycaster(raycaster: THREE.Raycaster, layer: number) {
  raycaster.layers.set(layer)
}

// 导出
export { enable, disable, disableAll, setRaycaster }
